home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / utility / cica2db.zip / CICA2DB.C next >
Text File  |  1991-02-09  |  4KB  |  176 lines

  1. /*
  2.    CICA2DB - Create a database importable file from cica's win3 index
  3.  
  4.     Author:         Hans van Oostrom
  5.                     hans@pine.circa.ufl.edu  INTERNET
  6.                     hans@ufpine              BITNET
  7.  
  8.     Date:           Feb 7, 1991
  9.  
  10.     Version:        1.00
  11.  
  12.     Modifications:  none
  13.  
  14.     Status:         Public Domain
  15.                     You need not to send any money to use this, it's
  16.                     absolutely free.  Also the source code is provided, so
  17.                     make all the modifications you want. If you like it you
  18.                     can let me know if you want to.
  19.  
  20.  
  21.     Compiled with Turbo C++ 1.00, also compatible with MSC 5.1
  22.  
  23. */
  24.  
  25. #include <stdio.h>
  26. #include <string.h>
  27.  
  28. /*** parse the filename and description ************************************/
  29. int ParseFile(char *line)
  30. {
  31.     char temp[80];
  32.     int i=1;
  33.     char *tp=temp;
  34.     
  35.     if (strlen(line)<5) 
  36.     {
  37.         line[0]='\0';
  38.         return 0;
  39.     }
  40.     
  41.     strcpy(temp,line);
  42.     line[0] = '\"';
  43.     while (!isspace(*tp))
  44.     {
  45.         line[i++]=*tp;
  46.         ++tp;
  47.     }
  48.     line[i++] = '\"';
  49.     line[i++] = ',';
  50.     line[i++] = '\"';
  51.     
  52.     while (isspace(*tp)) ++tp;
  53.     
  54.     while (*tp!='\n')
  55.     {
  56.         line[i++]=*tp;
  57.         ++tp;
  58.     }
  59.     line[i++] = '\"';
  60.     line[i++] = '\0';
  61.     
  62.     return 0;
  63. }
  64.     
  65.  
  66. /*** parse the directory name.  Starts with win3\ **************************/
  67. int ParseDir(char *line)
  68. {
  69.     char temp[80];
  70.     int i=1;
  71.     char *tp=temp;
  72.     
  73.     if (strlen(line)<5) 
  74.     {
  75.         line[0]='\0';
  76.         return 0;
  77.     }
  78.     
  79.     strcpy(temp,line);
  80.     tp = strstr(tp, "win3" );
  81.     if (tp==NULL)
  82.     {
  83.         line[0]='\0';
  84.         return 0;
  85.     }
  86.     line[0] = '\"';
  87.  
  88.  
  89.     while (*tp!='\n')
  90.     {
  91.         line[i++]=*tp;
  92.         ++tp;
  93.     }
  94.     line[i++] = '\"';
  95.     line[i++] = '\0';
  96.     
  97.     return 0;
  98. }
  99.  
  100.  
  101. /*** main program entry point *********************************************/
  102. void main(int argc, char *argv[])
  103. {
  104.     char line[80];
  105.     char dir[80];
  106.     FILE *in;
  107.     FILE *out;
  108.     char inname[80];
  109.     char outname[80];
  110.     int i;  
  111.     
  112.  
  113.     printf( "CICA2DB - Index to database converter\n");
  114.     printf( "      Version 1.00, Feb 7, 1991\n" );
  115.     printf( "        by Hans van Oostrom\n" );
  116.     printf( "      hans@pine.circa.ufl.edu\n\n");
  117.  
  118.     switch(argc)                        /* handle command line parameters */
  119.     {
  120.         case 1:
  121.             printf( "Input name:  " );
  122.             gets( inname );
  123.             printf( "Output name: ");
  124.             gets( outname );
  125.             break;
  126.         case 2:
  127.             strcpy(inname, argv[1]);
  128.             printf( "Output name: ");
  129.             gets( outname );
  130.             break;
  131.         case 3:
  132.             strcpy(inname, argv[1]);
  133.             strcpy(outname, argv[2]);
  134.             break;
  135.         default:
  136.             printf( "Usage: %s <inputfile> <outputfile>\n", argv[0] );
  137.             exit(1);
  138.     }
  139.  
  140.     if ((in=fopen(inname, "r"))==NULL)
  141.     {
  142.         printf( "Error opening file: %s\n", inname );
  143.         exit(2);
  144.     }
  145.     if ((out=fopen(outname, "w"))==NULL)
  146.     {
  147.         printf( "Error opening file: %s\n", outname );
  148.         exit(2);
  149.     }
  150.     
  151.     fgets(line, 80, in);
  152.     while (!feof(in))
  153.     {
  154.         if (fgets( line, 80, in )==NULL) break;
  155.  
  156.         switch(line[0])
  157.         {
  158.             case '\n':
  159.             case ' ':
  160.                 break;
  161.             case '*':
  162.                 ParseDir(line);
  163.                 if (line[0]!='\0') strcpy(dir, line);
  164.                 break;
  165.             default:
  166.                 ParseFile(line);
  167.                 if (line[0] != 0)
  168.                     fprintf( out, "%s,%s\n", dir, line );
  169.                 break;
  170.         }
  171.     }   
  172.     fclose(in);
  173.     fclose(out);
  174.     printf( "Conversion complete.\n" );
  175. }
  176.